﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Tycho.Runtime;

namespace Tycho.Peyote {
    /// <summary>
    /// Interaction logic for ObjectGlyph.xaml
    /// </summary>
    public partial class ObjectGlyph : UserControl {
        AnyObject _runtimeObject;

        public ObjectGlyph (AnyObject obj) {
            _runtimeObject = obj;
            InitializeComponent ();

            DataContext = this;
        }

        public IEnumerable<PropertyValue> Properties {
            get {
                AnyObject properties = _runtimeObject.InvokeMethod (_runtimeObject, Symbols.RuntimeGetProperty, Symbols.RuntimeProperties);
                List<PropertyValue> propertyNames = new List<PropertyValue> ();
                foreach (AnyObject property in properties) {
                    propertyNames.Add (new PropertyValue (((Symbol) property).ToString (), _runtimeObject.GetProperty (property).ToString ()));
                }
                return propertyNames;
            }
        }

        public IEnumerable<string> Methods {
            get {
                AnyObject methods = _runtimeObject.InvokeMethod (_runtimeObject, Symbols.RuntimeGetProperty, Symbols.RuntimeMethods);
                List<string> methodNames = new List<string> ();
                foreach (AnyObject method in methods) {
                    methodNames.Add (((Symbol) method).ToString ());
                }
                return methodNames;
            }
        }

        public class PropertyValue {
            public string Name { get; set; }
            public string Value { get; set; }

            public PropertyValue (string name, string value) {
                Name = name;
                Value = value;
            }
        }
    }
}
